<?php

header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Transfer-Encoding:utf-8");
header("Pragma: no-cache");
header('Content-Type: application/vnd.ms-excel');
header('Cache-Control: max-age=0');
header("Content-Disposition:filename=".date("Ymd").time().".xls");

echo iconv("UTF-8","Big-5","序號\t需求類型\t姓名\t手機\t住家電話\t公司電話\t住家地址\t大樓名稱\t公司地址\t公司名稱\tEmail\t聯絡人\t聯絡人電話\t物件用途\t建物面積1\t建物面積2\t室內面積1\t室內面積2\t土地面積1\t土地面積2\t車位數\t可接受機械\t重點區域1\t重點區域2\t指定大樓1\t指定大樓2\t路段1\t路段2\t物件案名1\t物件案名2\t捷運線1\t捷運站起點1\t捷運站終點1\t捷運線2\t捷運站起點2\t捷運站終點2\t緯度1\t經度1\t緯度2\t經度2\t公園1\t公園2\t學校1\t學校2\t商圈1\t商圈2\t行政區1\t行政區2\t總預算1\t總預算2\t每坪預算1\t每坪預算2\t投報率1\t投報率2\t承租營業用途\t屋齡\t物件案別\t落地窗座向\t該戶座向\t大樓座向\t指定樓層1\t指定樓層2\t指定樓層\t物件型式\t公共設施\t附屬配備\t管理\t房數1\t房數2\t廳數1\t廳數2\t衛數1\t衛數2\t套房數1\t套房數2\t分區使用\t樓地板高度\t客戶來源\t需求等級\t備注\t幣別\t面積單位\t狀態\t無效說明\t接待人\t指派主管\t原經紀人\t經紀人\t建檔時間\t\n");


$_string="'";
foreach($result as $key=>$val){
	
	echo $val->demand_id."\t";
	$t_str="";
	if($val->type_rent==1){
			$t_str="租";
	}
	if($val->type_sell==1){
			$t_str.="售";
	}
	if($val->type_consignment>0){
			$t_str.="代銷";
	}
	if($t_str!="")
		echo iconv("UTF-8","Big-5",$_string.$t_str)."\t";
	else
		echo "\t";
	if($val->name!="")
		echo iconv("UTF-8","Big-5",$_string.$val->name)."\t";
	else
		echo "\t";
	if($val->mobile!="")
		echo iconv("UTF-8","Big-5",$_string.$val->mobile)."\t";
	else
		echo "\t";
	if($val->home_phone!="")
		echo iconv("UTF-8","Big-5",$_string.$val->home_phone)."\t";
	else
		echo "\t";
	if($val->company_phone!="")
		echo iconv("UTF-8","Big-5",$_string.$val->company_phone)."\t";
	else 
		echo "\t";
	if($val->home_address!="")
		echo mb_convert_encoding($_string.$val->home_address,"Big-5","UTF-8")."\t";				
	else 
		echo "\t";
	if($val->building_name!="")
		echo iconv("UTF-8","Big-5",$_string.$val->building_name)."\t";
	else
		echo "\t";
	if($val->company_address!="")
		echo @iconv("UTF-8","Big-5",$_string.$val->company_address)."\t";
	else
		echo "\t";
	if($val->company_name!="") 
		echo @iconv("UTF-8","Big-5//ignore",$_string.$val->company_name)."\t";
	else
		echo "\t";
	if($val->email!="")
		echo iconv("UTF-8","Big-5",$_string.$val->email)."\t";
	else
		echo "\t";
	if($val->contact!="")
		echo iconv("UTF-8","Big-5",$val->contact)."\t";
	else
		echo "\t";	
	if($val->contact_phone!="")
		echo iconv("UTF-8","Big-5",$_string.$val->contact_phone)."\t";
	else
		echo "\t";
	//if(isset($object_usage[$val->object_usage]))
	//	echo iconv("UTF-8","Big-5",$object_usage[$val->object_usage])."\t";
	if($val->object_usage!="")
		echo iconv("UTF-8","Big-5",$_string.$val->object_usage)."\t";
	else
		echo "\t";
	if($val->building_area1!="")
		echo iconv("UTF-8","Big-5",$val->building_area1)."\t";
	else
		echo "\t";
	if($val->building_area2!="")
		echo iconv("UTF-8","Big-5",$val->building_area2)."\t";
	else
		echo "\t";
	if($val->indoor_area1!="")
		echo iconv("UTF-8","Big-5",$val->indoor_area1)."\t";
	else
		echo "\t";
	if($val->indoor_area2!="")
		echo iconv("UTF-8","Big-5",$val->indoor_area2)."\t";
	else
		echo "\t";
	if($val->land_area1)
		echo iconv("UTF-8","Big-5",$val->land_area1)."\t";
	else
		echo "\t";
	if($val->land_area2!="")
		echo iconv("UTF-8","Big-5",$val->land_area2)."\t";
	else
		echo "\t";
	if(isset($val->parking_number))
		echo iconv("UTF-8","Big-5",$_string.$val->parking_number)."\t";
	else
		echo "\t";
	if($val->acceptable_mechanical==1) 
		echo iconv("UTF-8","Big-5","可接受機械")."\t";
	else 
		echo "\t";

	if($val->key_areas1!="")
		echo iconv("UTF-8","Big-5",$_string.$val->key_areas1)."\t";
	else
		echo "\t";
	if($val->key_areas2)
		echo iconv("UTF-8","Big-5",$_string.$val->key_areas2)."\t";
	else
		echo "\t";
	if($val->specify_building1!="")
		echo iconv("UTF-8","Big-5",$_string.$val->specify_building1)."\t";
	else
		echo "\t";
	if($val->specify_building2!="")
		echo iconv("UTF-8","Big-5",$_string.$val->specify_building2)."\t";
	else
		echo "\t";
	if($val->sections1!="")
		echo mb_convert_encoding($val->sections1,"Big-5","UTF-8");		
	else
		echo "\t";
	if($val->sections2!="")
		echo iconv("UTF-8","Big-5",$val->sections2)."\t";
	else
		echo "\t";
	if($val->object_name1!="")
		echo mb_convert_encoding($val->object_name1,"Big-5","UTF-8");				
	else
		echo "\t";
	if($val->object_name2!="")
		echo iconv("UTF-8","Big-5",$val->object_name2)."\t";
	else
		echo "\t";
	if(isset($mrt_line[$val->mrt_line1]))
		echo iconv("UTF-8","Big-5",$mrt_line[$val->mrt_line1])."\t";
	else
		echo "\t";
	if(isset($mrt[$val->mrt_start1]))
		echo iconv("UTF-8","Big-5",$mrt[$val->mrt_start1])."\t";
	else
		echo "\t";
	if(isset($mrt[$val->mrt_until1]))
		echo iconv("UTF-8","Big-5",$mrt[$val->mrt_until1])."\t";
	else
		echo "\t";
	if(isset($mrt_line[$val->mrt_line2]))
		echo iconv("UTF-8","Big-5",$mrt_line[$val->mrt_line2])."\t";
	else
		echo "\t";
	if(isset($mrt[$val->mrt_start2]))
		echo iconv("UTF-8","Big-5",$mrt[$val->mrt_start2])."\t";
	else
		echo "\t";
	if(isset($mrt[$val->mrt_until2]))
		echo iconv("UTF-8","Big-5",$mrt[$val->mrt_until2])."\t";
	else
		echo "\t";
	if($val->range_east!="")
		echo iconv("UTF-8","Big-5",$_string.$val->range_east)."\t";
	else
		echo "\t";
	if($val->range_north!="")
		echo iconv("UTF-8","Big-5",$_string.$val->range_north)."\t";
	else
		echo "\t";
	if($val->range_west!="")
		echo iconv("UTF-8","Big-5",$_string.$val->range_west)."\t";
	else
		echo "\t";
	if($val->range_south!="")
		echo iconv("UTF-8","Big-5",$_string.$val->range_south)."\t";
	else
		echo "\t";
	if($val->park1!="")
		echo iconv("UTF-8","Big-5",$val->park1)."\t";
	else
		echo "\t";
	if($val->park2!="")
		echo iconv("UTF-8","Big-5",$val->park2)."\t";
	else
		echo "\t";
	if($val->school1!="")
		echo iconv("UTF-8","Big-5",$val->school1)."\t";
	else
		echo "\t";
	if($val->school2!="")
		echo iconv("UTF-8","Big-5",$val->school2)."\t";
	else
		echo "\t";
	if($val->circle1!="")
		echo iconv("UTF-8","Big-5",$val->circle1)."\t";
	else
		echo "\t";
	if($val->circle2!="")
		echo iconv("UTF-8","Big-5",$val->circle2)."\t";
	else
		echo "\t";
	if($val->administrative_area1!=""){
		echo @iconv("UTF-8","Big-5//ignore",$_string.$val->administrative_area1)."\t";
	}else
		echo "\t";
	if($val->administrative_area2!="")
		echo mb_convert_encoding($val->administrative_area2,"Big-5","UTF-8");				
	else
		echo "\t";
	if($val->total_budget1!="")
		echo iconv("UTF-8","Big-5",$_string.$val->total_budget1)."\t";
	else
		echo "\t";
	if($val->total_budget2!="")
		echo iconv("UTF-8","Big-5",$_string.$val->total_budget2)."\t";
	else
		echo "\t";
	if($val->budget_per_ping1!="")
		echo iconv("UTF-8","Big-5",$_string.$val->budget_per_ping1)."%\t";
	else
		echo "\t";
	if($val->budget_per_ping2!="")
		echo iconv("UTF-8","Big-5",$_string.$val->budget_per_ping2)."\t";
	else
		echo "\t";
	if($val->reported_rate1!="")
		echo iconv("UTF-8","Big-5",$_string.$val->reported_rate1)."\t";
	else
		echo "\t";
	if($val->reported_rate2!="")
		echo iconv("UTF-8","Big-5",$_string.$val->reported_rate2)."\t";
	else
		echo "\t";
	if($val->leasing_business_purposes!="")
		echo iconv("UTF-8","Big-5",$_string.$val->leasing_business_purposes)."\t";
	else
		echo "\t";
	if($val->year_of_construction!="")
		echo iconv("UTF-8","Big-5",$_string.$val->year_of_construction)."\t";
	else
		echo "\t";
	$oct="";
	if(strstr($val->object_case_type,'1'))
		$oct.="中古屋";
	if(strstr($val->object_case_type,'2')){
		if($oct=="")
			$oct.="預售";
		else
			$oct.="/預售";
	}
	if(strstr($val->object_case_type,'3')){
		if($oct=="")
			$oct.="標售";
		else
			$oct.="/標售";
	}
	if($oct!="")
		echo iconv("UTF-8","Big-5",$oct)."\t";
	else
		echo "\t";
	if(isset($windows[$val->windows]))
		echo iconv("UTF-8","Big-5",$windows[$val->windows])."\t";
	else
		echo "\t";
	if(isset($base_is_located[$val->facing_the_household]))
		echo iconv("UTF-8","Big-5",$base_is_located[$val->facing_the_household])."\t";
	else
		echo "\t";
	if(isset($base_is_located[$val->building_facing]))
		echo iconv("UTF-8","Big-5",$base_is_located[$val->building_facing])."\t";
	else
		echo "\t";
	if($val->designated_floors1!="")
		echo iconv("UTF-8","Big-5",$_string.$val->designated_floors1)."\t";
	else
		echo "\t";
	if($val->designated_floors2!="")
		echo iconv("UTF-8","Big-5",$_string.$val->designated_floors2)."\t";
	else
		echo "\t";
	if($val->floors!="")
		echo iconv("UTF-8","Big-5",$_string.$val->floors)."\t";
	else
		echo "\t";
	if(isset($object_styles[$val->object_styles]))
		echo iconv("UTF-8","Big-5",$object_styles[$val->object_styles])."\t";
	else
		echo "\t";
	if(isset($public_facilities[$val->public_facilities]))
		echo iconv("UTF-8","Big-5",$public_facilities[$val->public_facilities])."\t";
	else
		echo "\t";
	if(isset($affiliated_with[$val->accessories_with]))
		echo iconv("UTF-8","Big-5",$affiliated_with[$val->accessories_with])."\t";
	else
		echo "\t";
	if(isset($management[$val->management]))
		echo iconv("UTF-8","Big-5",$management[$val->management])."\t";
	else
		echo "\t";
	
	if($val->number_of_rooms1!="")
		echo iconv("UTF-8","Big-5",$_string.$val->number_of_rooms1)."\t";
	else
		echo "\t";
	if($val->number_of_rooms2!="")
		echo iconv("UTF-8","Big-5",$_string.$val->number_of_rooms2)."\t";
	else
		echo "\t";
	if($val->number_of_hall1!="")
		echo iconv("UTF-8","Big-5",$_string.$val->number_of_hall1)."\t";
	else
		echo "\t";
	if($val->number_of_hall2!="")
		echo iconv("UTF-8","Big-5",$_string.$val->number_of_hall2)."\t";
	else
		echo "\t";

	if($val->number_of_toilet1!="")
		echo iconv("UTF-8","Big-5",$_string.$val->number_of_toilet1)."\t";
	else
		echo "\t";
	if($val->number_of_toilet2!="")
		echo iconv("UTF-8","Big-5",$_string.$val->number_of_toilet2)."\t";
	else
		echo "\t";

	if($val->number_of_suite1!="")
		echo iconv("UTF-8","Big-5",$_string.$val->number_of_suite1)."\t";
	else
		echo "\t";
	if($val->number_of_suite2!="")
		echo iconv("UTF-8","Big-5",$_string.$val->number_of_suite2)."\t";
	else
		echo "\t";

	if(isset($land_use_zoning[$val->partition_the]))
		echo iconv("UTF-8","Big-5",$land_use_zoning[$val->partition_the])."\t";
	else
		echo "\t";
	if($val->floor_height!="")
		echo iconv("UTF-8","Big-5",$_string.$val->floor_height)."\t";
	else
		echo "\t";
	if(isset($customer_source[$val->customer_source]))
		echo iconv("UTF-8","Big-5",$customer_source[$val->customer_source])."\t";
	else
		echo "\t";
	if(isset($required_level[$val->required_level]))
		echo iconv("UTF-8","Big-5",$required_level[$val->required_level])."\t";
	else
		echo "\t";
	if($val->remark!="")
		echo iconv("UTF-8","Big-5",str_replace("\n", " ",$_string.$val->remark))."\t";
	else
		echo "\t";
	if(isset($currency[$val->currency]))
		echo iconv("UTF-8","Big-5",$currency[$val->currency])."\t";
	else
		echo "\t";
	if(isset($area_unit[$val->area_unit]))
		echo iconv("UTF-8","Big-5",$area_unit[$val->area_unit])."\t";
	else
		echo "\t";
	if($val->status==1)
		echo iconv("UTF-8","Big-5","有效")."\t";
	else
		echo iconv("UTF-8","Big-5","無效")."\t";
	if($val->invalid_description!="")
		echo iconv("UTF-8","Big-5",$_string.$val->invalid_description)."\t";
	else
		echo "\t";	
	if($val->front_man!="")
		echo iconv("UTF-8","Big-5",$_string.$val->front_man)."\t";
	else
		echo "\t";
	if($val->head!="")
		echo iconv("UTF-8","Big-5",$_string.$val->head)."\t";
	else
		echo "\t";
	if($val->original_broker!="")
		echo iconv("UTF-8","Big-5",$_string.$val->original_broker)."\t";
	else
		echo "\t";
	if($val->broker!="")
		echo iconv("UTF-8","Big-5",$_string.$val->broker)."\t";
	else
		echo "\t";
	echo iconv("UTF-8","Big-5",date("Y/m/d",$val->ctime))."\t\n";

}
?>